//
//  WTOXQTableViewController.m
//  PASystem
//
//  Created by michael on 16/9/21.
//  Copyright © 2016年 czd. All rights reserved.
//

#import "WTOXQTableViewController.h"

@interface WTOXQTableViewController ()
@property(nonatomic,strong)NSDictionary * dic;
@end

@implementation WTOXQTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];


     self.title = _string;
    self.view.backgroundColor = [UIColor whiteColor];
            [self loadData]; //加载网络数据
self.tableView.bounces = NO;


}
- (void)viewDidAppear:(BOOL)animated
{
self.tableView.frame = CGRectMake(0, 64, KScreenWidth, KScreenHeight-46-64);
     UIColor *myColor = [UIColor colorWithWhite:0.8 alpha:0.3];
    
    self.tableView.layer.borderWidth = 10;
    self.tableView.layer.borderColor = [myColor CGColor];

}
#pragma mark 加载网络数据
-(void)loadData{
    NSString * userId = [[NSUserDefaults standardUserDefaults]objectForKey:@"userId"];
    NSString * pwdId = [[NSUserDefaults standardUserDefaults]objectForKey:@"pwdId"];
    NSString * userHumber = [[NSUserDefaults standardUserDefaults]objectForKey:@"userHumber"];
    
 NSString *json =[NSString stringWithFormat: @"{'action':%@,'service': %@, 'userName':'%@','password':'%@', 'vaueJson':'{userid :%@,id:%@}'}",_action,_service,userId,pwdId,userHumber,_id];
     NSArray * array = @[@{@"arg0":json}];
    [HttpTools requestWithURL:BaseURL arrays:array method:Basemethod success:^(id JSON) {

       
     NSDictionary *dic = JSON[@"reason"];
        
    NSDictionary *dict = dic[@"attrs"];
//    NSLog(@"%@",dict);
    
    _dic = dict;
//    [_dataArray addObject:dict];
    

//     NSLog(@"11%@",_dataArray);
        
        [self.tableView reloadData];
       
    } failure:^(NSError *error) {
        
    }];
 
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return  7;
}
#pragma mark UITableView dataScource
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.row ==0) {
    
     UITableViewCell* cell = [[UITableViewCell alloc]init];
      UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, 80, cell.contentView.height)];
    label.text = @"标题:";
     label.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:label];
  UILabel *label2= [[UILabel alloc]initWithFrame:CGRectMake(label.right, label.top, KScreenWidth  -100, label.height)];
    label2.text = _dic[@"TITLE"];
    label2.textAlignment = NSTextAlignmentRight;
     label2.font = [UIFont systemFontOfSize:12];
    [cell.contentView addSubview:label2];
    return cell;

}
    if (indexPath.row ==1) {
    
     UITableViewCell* cell = [[UITableViewCell alloc]init];
      UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, 100, cell.contentView.height)];
    label.text = @"发起时间:";
     label.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:label];
  UILabel *label2= [[UILabel alloc]initWithFrame:CGRectMake(label.right, label.top,KScreenWidth -120, label.height)];
 NSString *string = _dic[@"BEGINTIME"];
  NSDateFormatter *fmt = [[NSDateFormatter alloc] init];
    fmt.dateFormat = @"MMM d, yyyy HH:mm:ss aa";
 fmt.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en-US"];
     NSDate *date = [fmt dateFromString:string];
     NSDateFormatter *fm = [[NSDateFormatter alloc] init];
    fm.dateFormat = @"yyyy-MM-dd";
     NSString *selfYear = [fm stringFromDate:date];
      label2.textAlignment = NSTextAlignmentRight;

    label2.text = selfYear;
     label2.font = [UIFont systemFontOfSize:12];
    [cell.contentView addSubview:label2];
    return cell;

}
if (indexPath.row ==2) {
    
     UITableViewCell* cell = [[UITableViewCell alloc]init];
      UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, 100, cell.contentView.height)];
    label.text = @"审议国家:";
     label.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:label];
  UILabel *label2= [[UILabel alloc]initWithFrame:CGRectMake(label.right, label.top, KScreenWidth  -120, label.height)];
    label2.text = [NSString stringWithFormat:@"%@",_dic[@"COUNTRY"]];
      label2.textAlignment = NSTextAlignmentRight;

     label2.font = [UIFont systemFontOfSize:12];
    [cell.contentView addSubview:label2];
    return cell;

}
if (indexPath.row ==3) {
    
         UITableViewCell* cell = [[UITableViewCell alloc]init];
      UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, 100, cell.contentView.height)];
    label.text = @"为相关法规或政策书面建言(条):";
    label.numberOfLines = 0;
              label.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:label];
  UILabel *label2= [[UILabel alloc]initWithFrame:CGRectMake(label.right, label.top,KScreenWidth  -120, label.height)];
    label2.text = [NSString stringWithFormat:@"%@",_dic[@"PROPOSAL"]];          label2.textAlignment = NSTextAlignmentRight;

     label2.font = [UIFont systemFontOfSize:12];
    [cell.contentView addSubview:label2];
    return cell;
}if (indexPath.row ==4) {
    
     UITableViewCell* cell = [[UITableViewCell alloc]init];
      UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, 100, cell.contentView.height)];
    label.text = @"问券回收(家):";
     label.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:label];
  UILabel *label2= [[UILabel alloc]initWithFrame:CGRectMake(label.right, label.top,KScreenWidth  -120, label.height)];
      label2.text = [NSString stringWithFormat:@"%@",_dic[@"RECOVERY"]];
      label2.textAlignment = NSTextAlignmentRight;

     label2.font = [UIFont systemFontOfSize:12];
    [cell.contentView addSubview:label2];
    return cell;

}if (indexPath.row ==5) {
    

 UITableViewCell* cell = [[UITableViewCell alloc]init];
      UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, 100, cell.contentView.height)];
    label.text = @"审议内容:";
     label.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:label];
  NSString *string = _dic[@"CONTENT"];
NSString *result = [string stringByReplacingOccurrencesOfString:@"&quot;" withString:@"\""];

result = [result stringByReplacingOccurrencesOfString:@"&lt;" withString:@"<"];
result = [result stringByReplacingOccurrencesOfString:@"&gt;" withString:@">"];


 UIWebView *web= [[UIWebView alloc]initWithFrame:CGRectMake(label.right, label.top, KScreenWidth-20-100,120)];
 web.delegate = self;
 [web loadHTMLString:result baseURL:nil];
 web.backgroundColor = [UIColor whiteColor];
       [cell.contentView addSubview:web];
    return cell;

}else {
    
     UITableViewCell* cell = [[UITableViewCell alloc]init];
      UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, 100, cell.contentView.height)];
    label.text = @"审议结果:";
     label.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:label];
  NSString *string = _dic[@"RESULT"];
NSString *result = [string stringByReplacingOccurrencesOfString:@"&quot;" withString:@"\""];

result = [result stringByReplacingOccurrencesOfString:@"&lt;" withString:@"<"];
result = [result stringByReplacingOccurrencesOfString:@"&gt;" withString:@">"];


 UIWebView *web= [[UIWebView alloc]initWithFrame:CGRectMake(label.right, label.top, KScreenWidth-20-100,120)];
 web.delegate = self;
 [web loadHTMLString:result baseURL:nil];
 web.backgroundColor = [UIColor whiteColor];
       [cell.contentView addSubview:web];
    return cell;

}
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
CGFloat H = 60;
if(indexPath.row ==5||indexPath.row ==6)
{
return 120;

}else{
return H;
}

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}




@end
